/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GraphPanel.java
 *
 * Created on 2011-10-07, 07:25:41
 */

package Visual.Graph;

import Engine.Host;
import USBThermometerLib.Sensor;
import Main.Main;
import Tools.ConfigurationManager;
import Tools.CharsetControl;
import Visual.MainForm;
import java.awt.Color;
import java.awt.Component;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JColorChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author pawelkn
 */
public class GraphPanel extends javax.swing.JPanel implements DropTargetListener {
    private static ResourceBundle bundle;

    private final Graph graph;
    private final Component parent;

    /** Creates new form GraphPanel */
    public GraphPanel(Component parent) {
        this.parent = parent;

        Locale locale = new Locale( ConfigurationManager.load().getLocale() );
        ResourceBundle.clearCache();
        bundle = ResourceBundle.getBundle("Bundle", locale, new CharsetControl());

        initComponents();
        
        this.setDropTarget(new DropTarget(this,this));
        this.setPreferredSize(parent.getSize());

        graph = new Graph(this);
        jPanel1.add(graph);
        jToolBar2.add(new GraphStatusPanel(graph));

        repaint();
    }

    public Component getInternalFrame() {
        return parent;
    }

    public void addSensor(final Sensor newSensor) {
        if (newSensor != null) {
            graph.addSensor(newSensor);
        }
    }

    public void close() {
        Main.getLocalhost().removeHostObserver(graph);
        MainForm.getInstance().removeVisualElement(parent);
    }

    public Graph getGraph() {
        return graph;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButton4 = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jButton3 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        jButton14 = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        jButton13 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jToolBar2 = new javax.swing.JToolBar();
        jPanel1 = new javax.swing.JPanel();

        setMinimumSize(new java.awt.Dimension(300, 250));

        jToolBar1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        jButton1.setIcon(new ImageIcon("graphics/magnifier--plus.png"));
        jButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);

        jButton2.setIcon(new ImageIcon("graphics/magnifier--minus.png"));
        jButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton2);
        jToolBar1.add(jSeparator1);

        jButton4.setIcon(new ImageIcon("graphics/magnifier-zoom-fit.png"));
        jButton4.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton4);
        jToolBar1.add(jSeparator2);

        jButton3.setIcon(new ImageIcon("graphics/cross-script.png"));
        jButton3.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton3);

        jButton11.setIcon(new ImageIcon("graphics/color.png"));
        jButton11.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton11.setFocusable(false);
        jButton11.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton11.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton11);
        jToolBar1.add(jSeparator4);

        jButton14.setIcon(new ImageIcon("graphics/guide.png"));
        jButton14.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton14.setFocusable(false);
        jButton14.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton14.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton14);
        jToolBar1.add(jSeparator3);

        jButton13.setText(bundle.getString("3MIN")); // NOI18N
        jButton13.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton13.setFocusable(false);
        jButton13.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton13.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton13);

        jButton12.setText(bundle.getString("30MIN")); // NOI18N
        jButton12.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton12.setFocusable(false);
        jButton12.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton12.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton12);

        jButton5.setText(bundle.getString("1H")); // NOI18N
        jButton5.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton5);

        jButton6.setText(bundle.getString("3H")); // NOI18N
        jButton6.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton6.setFocusable(false);
        jButton6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton6.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton6);

        jButton7.setText(bundle.getString("24H")); // NOI18N
        jButton7.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton7.setFocusable(false);
        jButton7.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton7.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton7);

        jButton8.setText(bundle.getString("72H")); // NOI18N
        jButton8.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton8.setFocusable(false);
        jButton8.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton8.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton8);

        jButton9.setText(bundle.getString("1MSC")); // NOI18N
        jButton9.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton9.setFocusable(false);
        jButton9.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton9.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton9);

        jButton10.setText(bundle.getString("3MSC")); // NOI18N
        jButton10.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));
        jButton10.setFocusable(false);
        jButton10.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton10.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton10);

        jToolBar2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jToolBar2.setFloatable(false);
        jToolBar2.setRollover(true);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel1.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 471, Short.MAX_VALUE)
            .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 471, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 471, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        new Thread(new Runnable() {
            @Override
            public void run() {
                Calendar c = Calendar.getInstance();
                c.setTime(new Date());
                c.add(Calendar.HOUR, -1);
                graph.setDateRange( c.getTime(), new Date() );
                graph.autorange();
                graph.setAutoShiftLeft(true);
                graph.repaint();
            }
        }).start();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        new Thread(new Runnable() {
            @Override
            public void run() {
                Calendar c = Calendar.getInstance();
                c.setTime(new Date());
                c.add(Calendar.HOUR, -3);
                graph.setDateRange( c.getTime(), new Date() );
                graph.autorange();
                graph.setAutoShiftLeft(true);
                graph.repaint();
            }
        }).start();
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        new Thread(new Runnable() {
            @Override
            public void run() {
                Calendar c = Calendar.getInstance();
                c.setTime(new Date());
                c.add(Calendar.HOUR, -24);
                graph.setDateRange( c.getTime(), new Date() );
                graph.autorange();
                graph.setAutoShiftLeft(true);
                graph.repaint();
            }
        }).start();
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        new Thread(new Runnable() {
            @Override
            public void run() {
                Calendar c = Calendar.getInstance();
                c.setTime(new Date());
                c.add(Calendar.HOUR, -72);
                graph.setDateRange(c.getTime(), new Date());
                graph.autorange();
                graph.setAutoShiftLeft(true);
                graph.repaint();
            }
        }).start();
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        new Thread(new Runnable() {
            @Override
            public void run() {
                Calendar c = Calendar.getInstance();
                c.setTime(new Date());
                c.add(Calendar.MONTH, -1);
                graph.setDateRange( c.getTime(), new Date() );
                graph.autorange();
                graph.setAutoShiftLeft(true);
                graph.repaint();
            }
        }).start();
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        new Thread(new Runnable() {
            @Override
            public void run() {
                Calendar c = Calendar.getInstance();
                c.setTime(new Date());
                c.add(Calendar.MONTH, -3);
                graph.setDateRange( c.getTime(), new Date() );
                graph.autorange();
                graph.setAutoShiftLeft(true);
                graph.repaint();
            }
        }).start();
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
        new Thread(new Runnable() {
            @Override
            public void run() {
                Calendar c = Calendar.getInstance();
                c.setTime(new Date());
                c.add(Calendar.MINUTE, -3);
                graph.setDateRange( c.getTime(), new Date() );
                graph.autorange();
                graph.setAutoShiftLeft(true);
                graph.repaint();
            }
        }).start();
    };//GEN-LAST:event_jButton13ActionPerformed

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
        new Thread(new Runnable() {
            @Override
            public void run() {
                Calendar c = Calendar.getInstance();
                c.setTime(new Date());
                c.add(Calendar.MINUTE, -30);
                graph.setDateRange( c.getTime(), new Date() );
                graph.autorange();
                graph.setAutoShiftLeft(true);
                graph.repaint();
            }
        }).start();
    }//GEN-LAST:event_jButton12ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        new Thread(new Runnable() {
            @Override
            public void run() {
                graph.autorange();
                graph.repaint();
            }
        }).start();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        new Thread(new Runnable() {
            @Override
            public void run() {
                graph.setGuideMode(false, null);
                graph.setZoomMode(true);
                graph.repaint();
            }
        }).start();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        new Thread(new Runnable() {
            @Override
            public void run() {
                Grid grid = graph.getGrid();
                double verticalDistance = grid.getVisibleHighValue() - grid.getVisibleLowValue();
                int newHighY = grid.getVeriticalPosition( grid.getVisibleHighValue() + verticalDistance / 2 );
                int newLowY = grid.getVeriticalPosition( grid.getVisibleLowValue() - verticalDistance / 2 );
                long horizontalDistance = grid.getVisibleRightDate().getTime() - grid.getVisibleLeftDate().getTime();
                int newRight = grid.getHorizontalPosition( new Date( grid.getVisibleRightDate().getTime() + horizontalDistance/2 ) );
                int newLeft = grid.getHorizontalPosition( new Date( grid.getVisibleLeftDate().getTime() - horizontalDistance/2 ) );
                graph.zoom(newLeft, newHighY, newRight, newLowY);
                repaint();
            }
        }).start();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        int count = graph.getSensors().size();
        Object[] possibilities = new Object[count];
        for( int i = 0; i < count; i++ ) {
            possibilities[i] = graph.getSensors().get(i).getName();
        }
        
        String s = (String)JOptionPane.showInputDialog(
                            parent,
                            bundle.getString("SELECT_A_SENSOR_TO_REMOVE:"),
                            bundle.getString("REMOVE_SENSOR"),
                            JOptionPane.PLAIN_MESSAGE,
                            null,
                            possibilities,
                            null);

        if( s != null ) {
            for( Sensor sensor : graph.getSensors() ) {
                if(s.equals(sensor.getName())) {
                    graph.removeSensor(sensor);
                    return;
                }
            }
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        // TODO add your handling code here:
        // TODO add your handling code here:
        int count = graph.getSensors().size();
        Object[] possibilities = new Object[count];
        for( int i = 0; i < count; i++ ) {
            possibilities[i] = graph.getSensors().get(i).getName();
        }

        String s = (String)JOptionPane.showInputDialog(
                            parent,
                            bundle.getString("SELECT_A_SENSOR_TO_COLOR_CHANGE:"),
                            bundle.getString("COLOR_CHANGE"),
                            JOptionPane.PLAIN_MESSAGE,
                            null,
                            possibilities,
                            null);

        if( s != null ) {
            for( Sensor sensor : graph.getSensors() ) {
                if(s.equals(sensor.getName())) {
                    Color color = JColorChooser.showDialog( parent, bundle.getString("CHOOSE_A_COLOR"), graph.getSensorColor(sensor) );
                    if( color != null ) {
                        graph.setSensorColor(sensor, color);
                    }
                    repaint();
                    return;
                }
            }
        }
    }//GEN-LAST:event_jButton11ActionPerformed

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
        // TODO add your handling code here:
        int count = graph.getSensors().size();
        Object[] possibilities = new Object[count];
        for( int i = 0; i < count; i++ ) {
            possibilities[i] = graph.getSensors().get(i).getName();
        }

        String s = (String)JOptionPane.showInputDialog(
                            parent,
                            bundle.getString("SELECT_A_SENSOR:"),
                            bundle.getString("GUIDE_MODE"),
                            JOptionPane.PLAIN_MESSAGE,
                            null,
                            possibilities,
                            null);

        if( s != null ) {
            for( Sensor sensor : graph.getSensors() ) {
                if(s.equals(sensor.getName())) {
                    graph.setZoomMode(false);
                    graph.setGuideMode(true, sensor);
                    return;
                }
            }
        }
    }//GEN-LAST:event_jButton14ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar2;
    // End of variables declaration//GEN-END:variables

    @Override
    public void dragEnter(DropTargetDragEvent arg0) {
    }

    @Override
    public void dragOver(DropTargetDragEvent arg0) {
    }

    @Override
    public void dropActionChanged(DropTargetDragEvent arg0) {
    }

    @Override
    public void dragExit(DropTargetEvent arg0) {
    }

    @Override
    public void drop(DropTargetDropEvent dtde) {
        List<DataFlavor> df = dtde.getCurrentDataFlavorsAsList();
        Transferable tr = dtde.getTransferable();
        for(DataFlavor d : df) {
            try {
                Object list = tr.getTransferData(d);
                if( list instanceof String ) {
                    Sensor newSensor = Main.findSensorByName((String)list);
                    if( newSensor != null ) {
                        addSensor(newSensor);
                        return;
                    }
                }
            } catch (Exception ex) {
                Logger.getLogger("USBThermometer").log(Level.ALL, null, ex);
            }
        }
    }
}
